import  pytest
import requests

from api import log
from api.api_factory import ApiFactory
from tools import html_parse, clear_data


class TestTenderList:
    #清除数据
    @classmethod
    def setup_class(cls):
        clear_data()

    #初始化
    @pytest.fixture(autouse=True)
    def setup(self):
        self.session = requests.session()
        #获取工厂对象
        self.api = ApiFactory(self.session)
    def teardown(self):
        self.session.close()
    def test_tender_list(self):
        try:
            #获取图片验证码接口
            self.api.api_get_register_login().api_img_code(123123)
            #获取手机验证码接口
            self.api.api_get_register_login().api_phone_code("13600001121",8888)
            #获取注册接口
            self.api.api_get_register_login().api_register("13600001121","test123",8888,666666)
            #获取登录接口
            self.api.api_get_register_login().api_login()
            #获取认证接口
            self.api.api_approve_trust().api_approve("天天","341226190001014214")
            #获取后台开户接口
            result =self.api.api_approve_trust().api_trust()
            #获取三方开户接口
            data = html_parse(result)
            self.session.post(url=data[0],data=data[1])
            log.info("三方开户的执行结果为{}".format(result.text))
            # 获取充值验证码接口
            self.api.api_recharge().api_img_code(456456)
            # 获取充值接口
            result = self.api.api_recharge().api_recharge()

            #获取三方充值接口
            data = html_parse(result)
            self.session.post(url=data[0], data=data[1])
            log.info("三方充值的执行结果为{}".format(result.text))
            #获取投资接口
            result =self.api.api_tender().api_tender(100)
            #获取三方投资接口
            data = html_parse(result)
            self.session.post(url=data[0], data=data[1])
            log.info("三方投资的执行结果为{}".format(result.text))
        except Exception as e:
            log.error(e)
            raise